package com.zl.data;

import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
import android.text.TextUtils;
import com.zl.data.manger.DataManger;

/**
 * @author ZL @朱林</a>
 * @Version 1.0
 * @Description TODO
 * @date 2021/01/13  10:07
 */
public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        if (TextUtils.equals(getCurrentProcessName(getApplicationContext()), BuildConfig.APPLICATION_ID)) {
            DataManger.init(this,AppConstant.DATA_PATH);
        }
    }


    private String getCurrentProcessName(Context context) {
        int pid = android.os.Process.myPid();
        ActivityManager mActivityManager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningAppProcessInfo appProcess : mActivityManager
                .getRunningAppProcesses()) {
            if (appProcess.pid == pid) {
                return appProcess.processName;
            }
        }
        return null;
    }
}
